<?php


namespace app\crm\model;

use app\crm\model\ShopPerson;
use app\admin\model\Common;
use app\crm\model\ShopPersonAchievementModel;
use think\facade\Db;

/**
 * 订单商品模型
 * @package app\shop\model
 * @author LIU
 * @create 2021-10-01
 */
class ProductItem extends Common
{
    /**
     * 表名
     * @var string
     */
    protected $name = 'product_item';

    public function getGoodsList()
    {
        $where = [
            ['status', '=', 1],
        ];
        $goods = $this->where($where)->select()->toArray();

        $return  = [];
        if(!empty($goods)){
            $goods_type = ItemType::where('status',1)->column('name','id');

            foreach ($goods as $k=>&$v){
                $data = [];
                $data['id'] = $v['id'];
                $data['name'] =$v['name'];
                $data['goods_price'] =$v['price'];
                $data['spec_name'] = '';
                $data['kingdee_code'] = '';
                $data['type_one'] = $v['type_one'];
                $data['type_one_text'] = isset($goods_type[$v['type_one']])?$goods_type[$v['type_one']]:'';
                $data['type_two'] = $v['type_two'];
                $data['type_two_text'] = isset($goods_type[$v['type_two']])?$goods_type[$v['type_two']]:'';
                $data['type_three'] = $v['type_three'];
                $data['type_three_text'] = isset($goods_type[$v['type_three']])?$goods_type[$v['type_three']]:'';

                $children = [];

                if(!empty($v['product_info'])){
                    $children = json_decode($v['product_info'],1);
                    foreach ($children as $kk=>&$vv){
                        $vv['goods_type'] = 0;
                        $vv['goods_alias_name'] = '';
                        $vv['business_type'] = '';
                        $vv['checked'] = '';
                        $vv['prestock_type'] = '';
                        $vv['out_num'] = '';
                        $vv['littleCount'] = '';
                        $vv['pay_price'] = $vv['package_price'];
                        $vv['kingdee_code'] = '';
                        $vv['type_one'] = '';
                        $vv['type_two'] = '';
                        $vv['type_three'] = '';
                    }
                }
                $data['children'] = $children;
                $return[]= $data;
            }
        }
        return $return;

    }


}
